import request from '@/utils/request'
import { genParam } from '@/utils/encrypt'

export function deleteImage(params) {
  const paramStr = genParam(params)

  return request({
    url: '/common/common/remove',
    method: 'post',
    data: paramStr
  })
}

export function getList(params) {
  console.log(params)
  genParam(params)

  return request({
    url: '/admin/alibabaproduct/list',
    method: 'get',
    params
  })
}

export function getInfo(id) {
  return request({
    url: '/admin/alibabaproduct/' + id + '/info',
    method: 'get'
  })
}

export function createAlibabaProduct(param) {
  // console.log(param)
  const paramStr = genParam(param)
  // console.log(paramStr)

  return request({
    url: '/admin/alibabaproduct/create',
    method: 'post',
    data: paramStr
  })
}

export function editAlibabaProduct(param) {
  const params = {
    title: param.title,
    img_url: param.img_url,
    images: param.images,
    main_video: param.main_video,
    stats: param.stats,
    redemption: param.redemption,
    platform_price: param.platform_price,
    integral: param.integral,
    recommennd: param.recommennd,
    top_parent_id: param.top_parent_id,
    sub_parent_id: param.sub_parent_id,
    rebate_integral: param.rebate_integral,
    parent_rebate_integral: param.parent_rebate_integral,
    sub_rebate_integral: param.sub_rebate_integral,
    fake_clicks: param.fake_clicks,
    fake_favours: param.fake_favours,
    fake_views: param.fake_views,
    fake_platform_sales: param.fake_platform_sales,
    is_booking: param.is_booking
  }
  if (param.leaf_parent_id) {
    params.leaf_parent_id = param.leaf_parent_id
  }
  const paramStr = genParam(params)
  console.log(paramStr)

  return request({
    url: '/admin/alibabaproduct/' + param.product_id + '/edit',
    method: 'put',
    data: paramStr
  })
}

export function deleteAlibabaProduct(param) {
  return request({
    url: '/admin/alibabaproduct/' + param.id + '/delete',
    method: 'delete'
  })
}
